package com.xinhe.cn.cpbox.controller;


import com.xinhe.cn.cpbox.service.ScripService;
import com.xinhe.cn.cpbox.entity.po.ScripSend;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HB
 * @date 2021-05-13
 */
@Api(value = "纸条相关接口", tags = {"纸条相关接口"})
@RestController
@RequestMapping(value = "/scrip")
public class ScripController {
    @Autowired
    ScripService scripService;

    @ApiOperation(value = "上传图片", notes = "上传图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "图片", dataTypeClass = MultipartFile.class)
    })
    @PostMapping("/uploadImage")
    public Object uploadImage(@RequestParam("file") MultipartFile file) {
        return scripService.uploadImage(file);
    }

    @ApiOperation(value = "检验文本(未开通权限，不用接)", notes = "检查一段文本是否含有违法违规内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "需要检查的文本", dataTypeClass = String.class)
    })
    @PostMapping("/checkMsg")
    public Object checkMsg(String content) {
        return scripService.checkMsg(content);
    }

    @ApiOperation(value = "检验图片(未开通权限，不用接)", notes = "校验一张图片是否含有违法违规内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "需要检查的图片", dataTypeClass = MultipartFile.class)
    })
    @PostMapping("/checkImg")
    public Object checkImg(MultipartFile file) throws Exception {
        return scripService.checkImg(file);
    }

    @ApiOperation(value = "删除纸条", notes = "删除纸条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scripId", value = "纸条的id", dataTypeClass = String.class)
    })
    @PostMapping("/deleteScrip")
    public Object deleteLottery(@RequestBody @ApiIgnore ScripSend ScripSend) {
        return scripService.deleteScrip(ScripSend);
    }

    @ApiOperation(value = "查看是否能免费发纸条接口", notes = "查看是否能免费发纸条接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "纸条类型(字符串)：0/1，男/女", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sendId", value = "查看人的openId", dataTypeClass = String.class)
    })
    @GetMapping("/findCanFreeSend")
    public Object findCanFreeSend(@RequestParam("type") String type,
                                  @RequestParam("sendId") String sendId) {
        return scripService.findCanFreeSend(type, sendId);
    }

    @ApiOperation(value = "发/修改纸条", notes = "发/修改纸条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scripId", value = "纸条id，如果是修改纸条此处需要填写要修改的Id，发纸条不需要填写", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "type", value = "字符串类型：0/1，男/女", dataTypeClass = String.class),
            @ApiImplicitParam(name = "content", value = "纸条内容（2-50字）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "picUrl", value = "图片数组（1-4张图），保存上传对象桶后的图片链接['xxx.jpg', 'yyy.jpg']，需转成字符串传递，不传对象", dataTypeClass = String.class),
            @ApiImplicitParam(name = "wechat", value = "微信，微信/qq必填一个", dataTypeClass = String.class),
            @ApiImplicitParam(name = "qq", value = "qq，微信/qq必填一个", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sendId", value = "发送人的openId", dataTypeClass = String.class)
    })
    @PostMapping("/sendScrip")
    public Object sendScrip(@RequestBody @ApiIgnore ScripSend ScripSend) {
        return scripService.sendScrip(ScripSend);
    }

    @ApiOperation(value = "查看是否还有能抽的纸条", notes = "查看是否还有能抽的纸条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "纸条类型(字符串)：0/1，男/女", dataTypeClass = String.class),
            @ApiImplicitParam(name = "getUserId", value = "查看人的openId", dataTypeClass = String.class)
    })
    @GetMapping("/findCanGetScrip")
    public Object findCanGetScrip(@RequestParam("type") String type,
                                  @RequestParam("getUserId") String getUserId) {
        return scripService.findCanGetScrip(type, getUserId);
    }

    @ApiOperation(value = "随机抽取纸条", notes = "随机抽取纸条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "纸条类型(字符串)：0/1，男/女", dataTypeClass = String.class),
            @ApiImplicitParam(name = "getUserId", value = "查看人的openId", dataTypeClass = String.class)
    })
    @GetMapping("/getRandomScrip")
    public Object getRandomScrip(@RequestParam("type") String type,
                                 @RequestParam("getUserId") String getUserId) {
        return scripService.getRandomScrip(type, getUserId);
    }

    @ApiOperation(value = "分页查询我发的纸条", notes = "分页查询我发的纸条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sendId", value = "发纸条人的openId", dataTypeClass = String.class),
            @ApiImplicitParam(name = "page", value = "页码，从1开始", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "size", value = "每页个数", dataTypeClass = Integer.class)
    })
    @GetMapping("/getMyScripSend")
    public Object getMyScripSend(@RequestParam("sendId") String sendId,
                                 @RequestParam("page") int page,
                                 @RequestParam("size") int size) {
        return scripService.getMyScripSend(sendId, page, size);
    }

    @ApiOperation(value = "分页查询我收的纸条", notes = "分页查询我发的纸条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getUserId", value = "收纸条人的openId", dataTypeClass = String.class),
            @ApiImplicitParam(name = "page", value = "页码，从1开始", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "size", value = "每页个数", dataTypeClass = Integer.class)
    })
    @GetMapping("/getMyScripGet")
    public Object getMyScripGet(@RequestParam("getUserId") String getUserId,
                                 @RequestParam("page") int page,
                                 @RequestParam("size") int size) {
        return scripService.getMyScripGet(getUserId, page, size);
    }
}

